<template>
	<view>
		<u-action-sheet :actions="list" :show="show" title="选择子账号" @select="switchLogin" :closeOnClickAction="true"
			@close="show=  false" cancelText="关闭"></u-action-sheet>
	</view>
</template>
<script setup>
	import {
		ref,
		reactive
	} from "vue";
	import {
		userSwitchLogin
	} from "@/api/module/mine.js";
	import {
		goSwitchTab
	} from "@/utils/common";
	import {
		useStore
	} from 'vuex';
	const store = useStore()
	const list = ref([]);
	const dataList = ref([]);
	const show = ref(false)
	const open = (data) => {
		dataList.value = data;
		list.value = [];
		data.forEach((v, i) => {
			list.value.push({
				id: v.id,
				name: `${v.name}（${v.cellphone}）`
			})
		})
		show.value = true
	}
	const switchLogin = (e) => {
		userSwitchLogin({
			id: e.id
		}).then(res => {
			uni.setStorageSync("token", res.token)
			uni.setStorageSync("userInfo", res.user)
			store.commit('changeUserType', 2)
			goSwitchTab('/pages/my/index');
		})
	}
	defineExpose({
		open
	});
</script>